﻿using LyData.Data;
using System;
using System.Data;
using System.Web;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_ContentMenu : System.Web.UI.UserControl
{
    public void Bind()
    {
        IDb db = new DbFactory().DriverDb();
        db.Open();
        DataTable table = db.DataTable("MenuId,MenuName,Attributer", "menu", string.Format("Attributer<901 AND SiteLanguage={0} AND Show=true", SiteInfo.SiteLanguage()), "Location ASC, OrderId ASC,MenuId ASC");
        db.Close();
        if (table != null)
        {
            table.Columns.Add("url");
            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow row = table.Rows[i];
                row.BeginEdit();
                row["url"] = MenuProvider.FormatContentManagerUrl(row["Attributer"].ToString(), row["MenuId"].ToString());
                row.EndEdit();
                if (!ManagerLogin.ValidateRole(string.Format("M{0}_", row["MenuId"].ToString())))
                {
                    table.Rows[i].Delete();
                }
            }
        }
        this.ContentMenuList.DataSource = table;
        this.ContentMenuList.DataTextField = "MenuName";
        this.ContentMenuList.DataValueField = "url";
        this.ContentMenuList.DataBind();
        ListItem item = new ListItem("栏目管理", "MenuAdd.aspx");
        this.ContentMenuList.Items.Insert(0, item);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.IsPostBack)
        {
            this.Bind();
        }
    }
}
